﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DHISInteroperability.Authentication;
using System.Text;

namespace DHISInteroperability.Tests
{
    [TestClass]
    public class AuthozationAgentTest
    {
        [TestMethod]
        public void Credential_Assignment()
        {
            AuthorizationAgent agent = new AuthorizationAgent("user", "password");

            Assert.AreEqual("user", agent.Username);
            Assert.AreEqual("password", agent.Password);
            Assert.IsNotNull(agent.AuthorizationText);
        }

        [TestMethod]
        public void Credential_Modification()
        {
            AuthorizationAgent agent = new AuthorizationAgent("user", "password");
            agent.ChangeLoginCredentials("username", "hard2guessPassword");

            Assert.AreEqual("username", agent.Username);
            Assert.AreEqual("hard2guessPassword", agent.Password);
            Assert.IsNotNull(agent.AuthorizationText);
        }

        [TestMethod]
        public void Authorization_Text()
        {
            AuthorizationAgent agent = new AuthorizationAgent("user", "password");

            byte[] credentialBytes = Encoding.UTF8.GetBytes(("user:password").ToCharArray());
            string expected = "Basic " + Convert.ToBase64String(credentialBytes);

            Assert.AreEqual(expected, agent.AuthorizationText);
        }
    }
}
